package cn.doctorpda.conference.presenter;

import com.google.gson.reflect.TypeToken;

import java.util.List;

import cn.doctorpda.conference.bean.SplashInfo;
import cn.doctorpda.conference.config.NetConfig;
import cn.doctorpda.conference.model.GetsplashModel;
import cn.doctorpda.conference.model.IPostFileModel;
import cn.doctorpda.conference.model.IPostModelSplash;
import cn.doctorpda.conference.okhttp.callback.StringCallback;
import cn.doctorpda.conference.okhttp.https.GetUrl;
import cn.doctorpda.conference.okhttp.https.HttpsUtils;
import cn.doctorpda.conference.utils.GsonUtil;
import cn.doctorpda.conference.utils.L;
import cn.doctorpda.conference.view.callbackview.ISplashView;
import okhttp3.Call;

/**
 * Created by huangjinlong on 2016/5/24.
 */
public class SplashBgPresenter {
    private ISplashView baseView;
    private IPostModelSplash model;

    public SplashBgPresenter(ISplashView baseView) {
        this.baseView = baseView;
        model = new GetsplashModel();
    }

    public void GetWel() {
        model.postNetSplashWorkStringData(GetUrl.appendClientInfo(NetConfig.GET_AD) + "&code=yihuitong_index_welc&site_id=2", new StringCallback() {
            @Override
            public void onError(Call call, Exception e) {
               baseView.splashError(call, e);
                L.d("欢迎图egg");
            }

            @Override
            public void onResponse(String response) {
                L.d("欢迎图gg" + response);
                try {
                    List<SplashInfo> info = GsonUtil.fromJson(response, new TypeToken<List<SplashInfo>>() {
                    });
                    baseView.welcomeResult(info.get(0));
                    L.d("欢迎图" + info.get(0).getContents().get(0).getHref_url());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
}
